﻿using AutoMapper;
using MediatR;
using Product.API.Applcation.Command.Product;
using Product.Domain;
using Product.Infrstructre.Impl;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;

namespace Product.API.Applcation.CommandHandlers.Product
{
    /// <summary>
    /// 产品修改
    /// </summary>
    public class ProductInfoUpdateCommandHandler : IRequestHandler<ProductInfoUpdateCommand, int>
    {
        protected readonly IbaseProductInfoRepository ibaseProductInfo;
        protected readonly IMapper mapper;

        public ProductInfoUpdateCommandHandler(IbaseProductInfoRepository ibaseProductInfo, IMapper mapper)
        {
            this.ibaseProductInfo = ibaseProductInfo;
            this.mapper = mapper;
        }

        public async Task<int> Handle(ProductInfoUpdateCommand request, CancellationToken cancellationToken)
        {

            return await ibaseProductInfo.UpdateAsync(mapper.Map<Products>(request.UpdateDTO));

        }
    }
}
